/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.inventory.actions;

import com.erp.erp.security.logic.SecurityLogic;
import com.erp.erp.security.pojo.Forms;
import com.erp.erp.security.pojo.Reports;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;

/**
 *
 * @author maha
 */
public class AjaxAction extends ActionSupport {

    public AjaxAction() {
    }

    public String getForms() throws Exception {
        HttpServletRequest request = ServletActionContext.getRequest();
        int moduleId = Integer.parseInt(request.getParameter("data"));
        SecurityLogic security = new SecurityLogic();
        Vector<Forms> moduleForms = security.getModuleForms(moduleId);

        String buffer = "";

        for (Forms forms : moduleForms) {

            buffer = buffer + ("<option value='" + forms.getFormSid() + "'>" + forms.getFormName() + "</option>") + "\n";

        }

        System.out.println(buffer);
        HttpServletResponse response = ServletActionContext.getResponse();
        response.getWriter().write(buffer);

        return null;
    }

    public String getReports() throws Exception {
        HttpServletRequest request = ServletActionContext.getRequest();
        int moduleId = Integer.parseInt(request.getParameter("data"));
        SecurityLogic security = new SecurityLogic();
        Vector<Reports> moduleForms = security.getModuleReports(moduleId);

        String buffer = "";

        for (Reports forms : moduleForms) {

            buffer = buffer + ("<option value='" + forms.getReportSid() + "'>" + forms.getReportName() + "</option>") + "\n";

        }

        System.out.println(buffer);
        HttpServletResponse response = ServletActionContext.getResponse();
        response.getWriter().write(buffer);

        return null;
    }
}
